/* --- General Styles --- */
body {
  font-family: "Luckiest Guy", cursive, sans-serif;
  background-color: #f0f8ff;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  user-select: none;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
  margin-bottom: 20px;
  background-color: #fff;
  padding: 20px;
  border-radius: 15px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  /* Return to a more constrained width, similar to original */
  width: 90%;
  max-width: 800px; /* Adjust as needed, smaller than before */
}

/* --- Controls Area (Mostly Original) --- */
#controls {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  /* max-width: 600px; */ /* Maybe remove this limit if container is wider */
  padding: 15px 10px;
  background-color: #ffd1dc;
  border-radius: 10px;
  margin-bottom: 20px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
  flex-wrap: wrap;
  gap: 10px;
}
.control-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
/* ... other control styles (button, select, label, timer) mostly unchanged ... */
#controls label {
  font-size: 1.2em;
  color: #555;
}
#controls select,
#controls button {
  padding: 8px 15px;
  border: none;
  border-radius: 20px;
  background-color: #ffcc00;
  color: #333;
  font-family: "Luckiest Guy", cursive, sans-serif;
  font-size: 1em;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.1s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#controls select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333333%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px auto;
  padding-right: 30px;
}
#controls button:hover {
  background-color: #ffdb4d;
}
#controls button:active {
  transform: scale(0.95);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
#timer,
#message {
  font-size: 1.2em;
  color: #e91e63;
  min-width: 80px;
  text-align: center;
}
#message {
  color: #4caf50;
  font-weight: bold;
}

/* --- Maze Area (Mostly Original Structure) --- */
#maze-area {
  display: flex;
  justify-content: center; /* Center maze+fireworks horizontally */
  align-items: flex-start;
  width: 100%;
  gap: 20px;
  position: relative;
}

/* --- UPDATED: Maze Grid Container Size --- */
#maze-grid-container {
  /* Allow it to take available width within maze-area */
  /* Set a flexible max-height using viewport height */
  max-width: calc(100% - 220px); /* Example: Leave space for fireworks */
  /* If fireworks are stacked below on small screens, this needs media query adjustment */
  max-height: 70vh; /* Allow significant vertical space */

  overflow: auto; /* Keep scrollbars if maze content exceeds container */
  border: 5px solid #a0522d;
  border-radius: 10px;
  background-color: #f5f5dc;
  padding: 5px; /* Padding inside the border */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  /* Ensure it doesn't shrink if content is small */
  flex-shrink: 1;
  flex-grow: 1; /* Allow it to grow */
}

#maze-grid {
  display: grid;
  /* *** CRITICAL: Ensure this line exists and is correct *** */
  position: relative;
  border: 1px solid #ddd;
  background-color: #fff;
  /* width/height set by JS */
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* --- Maze Cells (Original Styles) --- */
.cell {
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}
.wall {
  background-color: #8b4513;
  background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10" fill="%23a0522d"/><path d="M0 5L5 0L10 5L5 10Z" fill="%238B4513"/></svg>');
  border: 1px solid #654321;
  border-radius: 2px;
}
.path {
  background-color: #fff;
}
.start {
  background-color: #90ee90;
}
.end {
  background-color: #add8e6;
  color: #ff6347; /* font-size set by JS */
}

/* --- Player (Rabbit - Original Style) --- */
#player {
  /* *** CRITICAL: Ensure this line exists and is correct *** */
  position: absolute;
  /* width, height, top, left, background-size set by JS */
  background-image: url("rabbit.png");
  background-repeat: no-repeat;
  background-position: center;
  transition: top 0.1s linear, left 0.1s linear; /* Keep smooth transition */
  z-index: 10; /* Keep player on top */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* --- Fireworks Canvas (修复样式) --- */
#fireworks-canvas {
  width: 200px; /* Fixed width for fireworks */
  height: 300px; /* 默认高度，由JS动态调整 */
  border-radius: 10px;
  flex-shrink: 0; /* Prevent fireworks canvas from shrinking */
  background-color: rgba(0, 0, 0, 0.2); /* 轻微背景色让用户知道有这个元素 */
  display: block; /* 确保元素显示为块 */
  z-index: 5; /* 保证烟花在适当的层 */
  position: relative; /* 相对定位 */
}

/* --- Media Queries (Adjusted for new layout needs) --- */
@media (max-width: 768px) {
  #game-container {
    width: 95%; /* Slightly wider on small screens */
    max-width: none; /* Remove max-width constraint */
    padding: 10px;
  }
  #maze-area {
    flex-direction: column; /* Stack maze and fireworks */
    align-items: center; /* Center items when stacked */
  }
  #maze-grid-container {
    /* When stacked, allow it to use most of the width */
    max-width: 95%;
    max-height: 60vh; /* Adjust height for stacked view */
    order: 1; /* Ensure maze is above fireworks */
  }
  #fireworks-canvas {
    width: 90%; /* Make canvas wider */
    max-width: 300px;
    height: 150px; /* Fixed height when stacked */
    margin-top: 15px;
    order: 2; /* Ensure fireworks are below maze */
  }
}

/* 级别选择器容器 - 更宽松的布局 */
#level-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px; /* 减小间距 */
  max-width: 450px; /* 增加宽度以容纳更多按钮 */
  justify-content: center;
  padding: 4px; /* 减小内边距 */
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.3);
}

/* 级别按钮样式 - 更紧凑 */
.level-button {
  width: 30px; /* 减小按钮大小 */
  height: 30px;
  border-radius: 50%;
  background-color: #ffcc00;
  border: 2px solid #ff9900;
  color: #333;
  font-family: "Luckiest Guy", cursive;
  font-size: 13px; /* 稍微减小字号 */
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  margin: 0; /* 确保没有额外边距 */
  padding: 0; /* 确保没有额外内边距 */
}

.level-button:hover {
  transform: scale(1.1);
  background-color: #ffdb4d;
}

.level-button.active {
  background-color: #ff6b6b;
  color: white;
  border-color: #ff0000;
  transform: scale(1.15);
  box-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
}

/* 声音按钮 */
.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #4caf50;
  border: none;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-button:hover {
  background-color: #3e8e41;
}

.icon-button.muted {
  background-color: #f44336;
}

/* 提高迷宫容器的最大高度，尤其在高级别 */
#maze-grid-container {
  max-height: 80vh; /* 增加高度比例 */
  max-width: calc(100% - 220px);
}

/* 媒体查询中的相应调整 */
@media (max-width: 768px) {
  #maze-grid-container {
    max-height: 70vh;
    max-width: 95%;
  }

  #level-container {
    max-width: 320px; /* 在小屏幕上仍然保持较宽 */
    overflow-y: auto;
    max-height: 85px; /* 稍微减小高度 */
  }

  .level-button {
    width: 26px; /* 在小屏幕上更小 */
    height: 26px;
    font-size: 11px;
  }
}

/* 更大屏幕上的调整 */
@media (min-width: 1200px) {
  #game-container {
    max-width: 95vw;
  }

  #maze-grid-container {
    max-height: 85vh;
  }
}
